<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">
	<!-- Theme style -->
	<link rel="stylesheet" href="../../../adminlte/dist/css/AdminLTE.min.css">
	<link rel="stylesheet" href="../../../layui/css/layui.css">
	<link rel="stylesheet" href="../../../css/byking.css">
	<link rel="stylesheet" href="../../../adminlte/dist/css/skins/_all-skins.min.css">
</head>
<body id="modifyrole">
	<div class="byking-form">
		<form class="layui-form" action="">

			<div class="layui-form-item">
				<label class="layui-form-label" style="width:90px">角色名称</label>
				<div class="layui-input-block">
					<input type="text" id="role_name" name="role_name" required lay-verify="required"
						placeholder="请输入角色" value="{{role.role_name}}" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" style="width:90px">角色信息</label>
				<div class="layui-input-block">
					<input type="text" id="role_info" name="role_info" required lay-verify="required"
						placeholder="请输入角色信息" value="{{role.role_info}}" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:90px">状态</label>
			    <div class="layui-input-block">
			      <select name="status" lay-verify="required" id="status">
			        <option value="1" :selected="role.status==1">禁用</option>
			        <option value="0" :selected="role.status==0">启用</option>
			      </select>
			    </div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn " lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<!-- jQuery -->
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<!-- jquery.cookie -->
	<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<!-- layer -->
	<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
	<!-- vue -->
	<script src="http://cdn.jsdelivr.net/vue/1.0.7/vue.min.js"></script>
	<script src="../../../layui/layui.js"></script>
	<script src="../../../js/byking.js"></script>
	<script src="../../../js/hostconfig.js"></script>

	<script>
/* 	function initpage(){
		var guid = $byking.getUrlParam("guid");
		var url = $hostconfig.sysAuthHost+"/role/info?guid="+guid;
		$byking.getJSON(url,function(data){
			var info = data.data;
			$("#guid").val(info.guid);
			$("#role_name").val(info.role_name);
			$("#role_info").val(info.role_info);
			$("#status").val(status);
		},function(data){});
	}
	 */
	var guid = $byking.getUrlParam("guid");
	 
	var modifyrole = new Vue({
        el: "#modifyrole",
        data: {
        	role:null
        },
        methods: {
        	getRoleInfo: function() {
        		
        		var url = $hostconfig.sysAuthHost+"/role/info?guid="+guid;
        		$byking.getJSONWithToken(url,function(data){
        			modifyrole.role = data.data;
        			setTimeout(function () { 
    					var form = layui.form();
    					form.render("select");
    			    }, 100);
        		},function(data){
        			layer.msg(data.responseJSON.message);
        		});
        	}
        }
    });
	
	modifyrole.getRoleInfo();
	
	var submitflag = true;
	layui.use('form', function() {
		var form = layui.form();
		//监听提交
		form.on('submit(formDemo)', function(data) {
			$(".layui-btn:first").attr("disabled","disabled");
			var data = data.field;
			data.guid = guid;
			data.update_by = $byking.getCookieValue("user_guid");
			data.user_guid = $byking.getCookieValue("user_guid");
			if(!submitflag){
				return false;
			}
			submitflag = false;
			var url = $hostconfig.sysAuthHost+"/role/add";
			$byking.postJSONWithToken(url,data,function(data){
				layer.msg("新增成功");
				var index = parent.layer.getFrameIndex(window.name);
				parent.refrehRole();
				parent.layer.close(index);
			},function(data){
				$(".layui-btn:first").removeAttr("disabled"); 
				layer.msg(data.responseJSON.message, {icon:5});
			});
			return false;
		});
	});
	</script>
</body>
</html>